<template>
  <div class="container">
    <div class="title" style=" text-align: left;">更新LOGO</div>
    <div class="wrap">
      <el-row>
        <el-col :lg="16" :md="20" :sm="24" :xs="24">
          <el-form :model="form" status-icon ref="form" label-width="100px" @submit.native.prevent>
            <el-form-item label="地址" prop="url">
              <el-input size="medium" v-model="form.url" placeholder="请填写地址" disabled="disabled"></el-input>
			  <el-upload 
			  ref="upload" 
			  class="upload-demo" 
			  :action="2222" 
			  :headers="headers" 
			  :on-success="onSuccessFile" 
			  :on-error="onErrorFile" 
			  :before-upload="beforeUpload" 
			  :on-progress="onProgressFile" 
			  name="file" 
			> 
			  <el-button 
				size="mini" 
				icon="el-icon-folder-add" 
				plain 
				type="primary" 
				>上传</el-button 
			  > 
			</el-upload>
			
			<img class="img" :src="img" style="width: 200px;"/>
			
            </el-form-item>
            <el-form-item class="submit">
              <el-button type="primary" @click="submitForm('form')" :loading="loading">保 存</el-button>
              <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { Logo } from '@/model/logo'

export default {
  data() {
    return {
	  img:null,
      form: {
      },
      loading: false,
    }
  },
  methods: {
	async beforeUpload(file){
		let fd = new FormData();
		fd.append('files',file);//传⽂件
		fd.append('no','11111');//传其他参数
		
    	const logos = await Logo.upload(fd)
	    //this.img=logos[0].url
		 console.info(2222);
		 console.info(logos);
		  console.info(logos[0].url);
		  this.img=logos[0].url
		  this.form.url=logos[0].url
		
	
		//axios.post('cloudFile/recruit/file',fd).then(function(res){
		//	this.$data.img=res[0].url
		//	alert('成功');
		//	alert(this.$data.img);
		//})
		return false //屏蔽了action的默认上传
	},
	
	
    async submitForm(formName) {
      try {
        this.loading = true
        const res = await Logo.createLogo(this.form)
        this.loading = false
        if (res.code < window.MAX_SUCCESS_CODE) {
          this.$message.success(`${res.message}`)
          // 清空输入框，方便继续添加LOGO
          this.resetForm(formName)
        }
      } catch (error) {
        this.loading = false
        console.log(error)
      }
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
  },
}
</script>

<style lang="scss" scoped>
.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;
    border-bottom: 1px solid #dae1ec;
  }

  .wrap {
    padding: 20px;
  }

  .submit {
    float: left;
  }
}
</style>
